package com.xauto.pioneer.appuser.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**订单结算详情 与OrderDetailInfo模型类似
 * Created by Ellis.Li on 2017/5/12.
 */
public class OrderCostInfo extends BaseModel<OrderCostInfo> {

    /** 车辆订单ID*/
    public String car_order_id;
    /** 车辆订单编号*/
    public String car_order_no;
    /** 车辆订单状态ID*/
    public String car_order_status_id;
    /** 车辆订单状态名称*/
    public String car_order_status_name;
    /** 车辆订单备注*/
    public String car_order_remark;
    /** 车辆订单备注颜色(0-黑色/1-红色)*/
    public String car_order_remark_style_color;
    /** 订单开始时间(unix_time)*/
    public String order_start_time;
    /**订单结束时间(unix_time)*/
    public String order_end_time;
    /** 计费开始时间(unix_time)*/
    public String order_charge_start_time;
    /** 计费结束时间(unix_time)*/
    public String order_charge_end_time;
    /** 总计*/
    public String total_amount;
    /** 格式化(10.00元)*/
    public String total_amount_format;
    /** */
    public BillChargeInfo billing_charge_info;
    /** */
    public List<OrderTotalInfo> order_total_list;
    /** */
    public Payment payment_info;
    /** */

    public VoucherInfo voucher_info;

    @Override
    public OrderCostInfo parse(JSONObject jsonObject) {
        if(jsonObject != null) {
            car_order_id = jsonObject.optString("car_order_id");
            car_order_no = jsonObject.optString("car_order_no");
            car_order_status_id = jsonObject.optString("car_order_status_id");
            car_order_status_name = jsonObject.optString("car_order_status_name");
            car_order_remark = jsonObject.optString("car_order_remark");
            car_order_remark_style_color = jsonObject.optString("car_order_remark_style_color");
            order_start_time = jsonObject.optString("order_start_time");
            order_end_time = jsonObject.optString("order_end_time");
            order_charge_start_time = jsonObject.optString("order_charge_start_time");
            order_charge_end_time = jsonObject.optString("order_charge_end_time");
            total_amount = jsonObject.optString("total_amount");
            total_amount_format = jsonObject.optString("total_amount_format");
            billing_charge_info = new BillChargeInfo().parse(jsonObject.optJSONObject("billing_charge_info"));
            JSONArray totalList = jsonObject.optJSONArray("order_total_list");
            if (totalList != null){
                order_total_list = new ArrayList<OrderTotalInfo>();
                for (int i=0,length = totalList.length();i<length;i++){
                    order_total_list.add(new OrderTotalInfo().parse(totalList.optJSONObject(i)));
                }
            }
            payment_info = new Payment().parse(jsonObject.optJSONObject("payment_info"));
            voucher_info = new VoucherInfo().parse(jsonObject.optJSONObject("voucher_info"));
            return this;
        }
        return null;
    }

    @Override
    public String toString() {
        return "OrderCostInfo{" +
                "car_order_id='" + car_order_id + '\'' +
                ", car_order_no='" + car_order_no + '\'' +
                ", car_order_status_id='" + car_order_status_id + '\'' +
                ", car_order_status_name='" + car_order_status_name + '\'' +
                ", car_order_remark='" + car_order_remark + '\'' +
                ", car_order_remark_style_color='" + car_order_remark_style_color + '\'' +
                ", order_start_time='" + order_start_time + '\'' +
                ", order_end_time='" + order_end_time + '\'' +
                ", order_charge_start_time='" + order_charge_start_time + '\'' +
                ", order_charge_end_time='" + order_charge_end_time + '\'' +
                ", total_amount='" + total_amount + '\'' +
                ", total_amount_format='" + total_amount_format + '\'' +
                ", billing_charge_info=" + billing_charge_info +
                ", order_total_list=" + order_total_list +
                ", payment_info=" + payment_info +
                ", voucher_info=" + voucher_info +
                '}';
    }
}
